import { CARD } from '../../constant';
import { byPkorgFiter, fiterDefdoc, fiterLrzxOrg } from '../../../../common/util/fiterUtils';

/**
* @description: 表体编辑前事件
* @param: moduleId 区域编码
* @param: key 当前字段编码
* @return: 布尔 true表示可编辑
*/
export function beforeTableEvent(props, moduleId, key, value, index, record, status) {
        if ( (key == 'vbdef3' || key == 'vbdef4')) {
                //一级部门、二级部门（参照利润中心部门）
                let vbdef2 = props.cardTable.getValByKeyAndIndex(CARD.table_code, index, 'vbdef2').value;
                let where = "def1 in (select pk_org from org_orgs where dr=0 and name in (select name from org_orgs where pk_org='"+vbdef2+"')) and def7='Y'";
                fiterDefdoc(props, moduleId, key, where);
        }
        if ( key == 'vbdef2')  {
                //机构编码（参照业务单元）
                let isDataPowerEnable = false;
                let isMultiSelectedEnabled = false;
                fiterLrzxOrg(props, moduleId, key, isDataPowerEnable, isMultiSelectedEnabled);
        }
        if ( key == 'psncode')  {
                //BQQ（6位工号）（参照人员档案）
                let pk_org = props.form.getFormItemsValue(CARD.form_id, 'pk_org').value;
                let isMultiSelectedEnabled = false;
                byPkorgFiter(props, moduleId, key, pk_org, isMultiSelectedEnabled);
        }
        return true;
}
